package com.example.administrator.myproject.user

import android.support.v4.app.FragmentActivity
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView

import com.example.administrator.myproject.R
import com.example.administrator.myproject.bean.Collect

class ShouAdapter(private val mContext: FragmentActivity?) : RecyclerView.Adapter<ShouAdapter.Holder>() {
    private var lists: List<Collect>? = null
    private val inflater: LayoutInflater

    override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): Holder {
        val view = inflater.inflate(R.layout.shou_item, viewGroup, false)
        return Holder(view)
    }

    override fun onBindViewHolder(holder: Holder, i: Int) {
        holder.tv1.text = lists!![i].name
        holder.tv2.text = "￥" + lists!![i].money.toString()
        holder.tv3.text = "数量：" + lists!![i].coum!!
        holder.tv6.text = lists!![i].createdAt
        if (lists!![i].state == "1") {
            holder.tv4.text = "等待商家接单"
        } else if (lists!![i].state == "2") {
            holder.tv4.text = "商家已接单"
        }
        else if (lists!![i].state == "3") {
            holder.tv4.text = "派送中"
        }
        else if (lists!![i].state == "4") {
            holder.tv4.text = "已送达"
        }
        if (lists!![i].name!!.equals("拌饭")) {
            holder.imageView.setImageDrawable(mContext!!.resources.getDrawable(R.drawable.laodiexie))
        } else if (lists!![i].name!!.equals("米饭")) {
            holder.imageView.setImageDrawable(mContext!!.resources.getDrawable(R.drawable.refeng))
        } else if (lists!![i].name!!.equals("米线")) {
            holder.imageView.setImageDrawable(mContext!!.resources.getDrawable(R.drawable.nanxie))
        } else if (lists!![i].name!!.equals("面")) {
            holder.imageView.setImageDrawable(mContext!!.resources.getDrawable(R.drawable.kuzi_9_fen))
        } else {
            holder.imageView.setImageDrawable(mContext!!.resources.getDrawable(R.drawable.mian_fan))
        }
    }

    override fun getItemCount(): Int {
        return if (lists == null) 0 else lists!!.size
    }

    fun setData(list: List<Collect>) {
        this.lists = list
        notifyDataSetChanged()
    }

    inner class Holder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val imageView: ImageView
        val tv1: TextView
        val tv2: TextView
        val tv3: TextView
        val tv4: TextView
        val tv6: TextView

        init {
            imageView = itemView.findViewById(R.id.shou_iv)
            tv1 = itemView.findViewById(R.id.shou_tv1)
            tv2 = itemView.findViewById(R.id.shou_tv2)
            tv3 = itemView.findViewById(R.id.shou_tv3)
            tv4 = itemView.findViewById(R.id.shou_tv4)
            tv6 = itemView.findViewById(R.id.shou_tv6)
        }
    }

    init {
        this.inflater = LayoutInflater.from(mContext)
    }
}
